//1、从本地sessionStorage去除token字符串
if (!sessionStorage.getItem('token')) {
  window.location.href = '/login.html';
}

//2、定义方法，获取用户基本信息
var getInfo = function () {
  getInfoAPI({}, res => {
    let { nickname, user_pic, username } = res.data.data;
    if (nickname == null) {
      nickname = username
    }
    $('.username').html(nickname);
    if (user_pic == null) {
      let firstletter = nickname[0].toUpperCase();
      $('.avatar').html(firstletter).css('display', 'inline-block')
    } else {
      $('.avatar').hide();
      $('.layui-nav-img').attr('src', user_pic).show();
    }
  })
}
getInfo();

//退出点击事件
$('#logout').on('click', () => {
  layer.confirm('说走就走吗？所以爱会消失？', { icon: 3, title: '提示' }, function (index) {
    layer.close(index); //关闭层
    sessionStorage.removeItem('token');
    window.location.href = "/login.html"
  });
})